using System.Windows.Forms;
using HogoLogic;

namespace ProjectView
{
	public partial class ProjectViewForm : Form
	{
		#region Singletone
		private ProjectViewForm()
		{
			InitializeComponent();
		}

		static public readonly ProjectViewForm Instance = new ProjectViewForm();
		#endregion

		public DialogResult ShowDialog(HogoProjectList projects)
		{
			projectListControl.ShowProjects(projects);
			SetupUI(projects);
			return ShowDialog();
		}

		private void SetupUI(HogoProjectList projects)
		{
			//Set "open project" radio button enable
			openRadio.Enabled = projects != null && projects.ProjectCount > 0;

			//choose default variant
			if (openRadio.Enabled)
				openRadio.Checked = true;
			else
				initRadio.Checked = true;
		}


		public ProjectSelectionResult Result
		{
			get
			{
				if (initRadio.Checked)
					return ProjectSelectionResult.Init;
				if (checkoutRadio.Checked)
					return ProjectSelectionResult.Clone;
				if (makeRadio.Checked)
					return ProjectSelectionResult.Make;
				if (openRadio.Checked)
					return new ProjectSelectionResult(projectListControl.SelectedProject);
				return ProjectSelectionResult.Empty;
			}
		}
	}
}